﻿namespace MicroCloud.Audit.Database
{
    /// <summary>
    /// 审计操作信息数据实体映射配置
    /// </summary>
    public class AuditOperationConfiguration : EntityTypeConfigurationBase<AuditOperation, long>
    {
        /// <summary>
        /// 重写以实现实体类型各个属性的数据库配置
        /// </summary>
        /// <param name="builder">实体类型创建器</param>
        public override void Configuration(EntityTypeBuilder<AuditOperation> builder)
        {
            builder.HasIndex(m => m.FunctionName).SetIndex("FunctionName");
            builder.HasIndex(m => m.ResultType).SetIndex("ResultType");
            builder.HasIndex(m => m.CreatedTime).SetIndex("CreatedTime");
            
            switch (DbContextOptions?.DatabaseType)
            {
                case DatabaseType.SqlServer:
                case DatabaseType.PostgreSql:
                case DatabaseType.Oracle:
                    builder.HasIndex(m => m.UserId).SetIndex("UserId");
                    builder.HasIndex(m => m.Ip).SetIndex("Ip");
                    break;
            }

            ConfigurationAppend(builder);
        }

    }
}
